package com.cdxy.dmr.repository;

import com.cdxy.dmr.dataObject.UserSaveDO;
import com.cdxy.dmr.mapper.UserSaveMapper;
import com.cdxy.enums.SaveTypeEnum;
import com.cdxy.model.dto.base.mybatis.BaseRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 用户收藏表 服务实现类
 * </p>
 *
 * @author autoGenCode
 * @since 2020-03-05
 */
@Repository
public class UserSaveRepository extends BaseRepository<UserSaveMapper, UserSaveDO> {
    /**
     * 获取收藏数据
     *
     * @param businessId
     * @param axUid
     * @param saveTypeEnum
     * @return
     */
    public UserSaveDO getByBusinessIdAndAxUidAndType(Integer businessId, Integer axUid, SaveTypeEnum saveTypeEnum) {
        return this.baseMapper.selectOne(this.queryWrapper()
                .eq(UserSaveDO::getBusinessId, businessId)
                .eq(UserSaveDO::getAxUid, axUid)
                .eq(UserSaveDO::getType, saveTypeEnum.name())
                .last("LIMIT 1"));
    }

    /**
     * 获取收藏数据
     *
     * @param businessId
     * @param axUid
     * @param saveTypeEnum
     * @return
     */
    public List<UserSaveDO> listByBusinessIdAndAxUidAndType(List<Integer> businessId, Integer axUid, SaveTypeEnum saveTypeEnum) {
        return this.baseMapper.selectList(this.queryWrapper()
                .in(UserSaveDO::getBusinessId, businessId)
                .eq(UserSaveDO::getAxUid, axUid)
                .eq(UserSaveDO::getType, saveTypeEnum.name()));
    }

}
